<%--
    Document   : setting
    Created on : Feb 2, 2013, 11:24:59 PM
    Author     : Vrety
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Setting Page</title>
        <script src="js/jquery.js"></script>
        <link href="css/register.css" rel="stylesheet" type="text/css">
    </head>
    <script type="text/javascript">
        //Check validate input password, email
        function validatePass(p1, p2) {
            if (p1.value != p2.value) {
                alert('Mật khẩu không trùng khớp!');
            }
            else{
                p2.setCustomValidity('');
            }
        }
        function validateEmail(e1, e2) {
            if (e1.value != e2.value) {
                e2.setCustomValidity('Email không trung khớp!');
            }
            else{
                e2.setCustomValidity('');
            }
        }
        //Check not empty
        function checkvalidUpdate(txtPassword,txtNewpassword,re_InputPassWord) {
            if (txtPassword === '' ||txtNewpassword === ''||re_InputPassWord === '' ) {
                alert ('Hãy nhập đầy đủ thông tin ');
                return false;
            }

            document.forms["ChangepassForm"].submit();
        }
        // Hidden form update information
        function declare(){
            document.getElementById("changeInfoForm").style.visibility ='hidden';
        }
        function showChangepassword() {
            document.getElementById("changepassLink").style.visibility ='hidden'; // show
            document.getElementById("changeInfoForm").style.visibility = 'visible'; // show
        }
        function changePassword(txtPassword,txtNewpassword,re_InputPassWord){
            
            if (txtPassword === '' ||txtNewpassword === ''||re_InputPassWord === '' ) {

                alert ('Hãy nhập đầy đủ thông tin ');
                return false;
            } else
            if ($("#re_InputPassWord").val()!=$("#InputNewPassword").val()){
                document.getElementById("msgError").innerHTML="Mật khẩu không trùng khớp!";
                return;
            }

            var email = $("#customerEmail").val();
            var oldPw = $("#InputPassWord").val();
            var newPw = $("#InputNewPassword").val();
            $.ajax({
                url: "ControllerServlet",
                type: "post",
                data:
                    {customerEmail:email,oldPassword:oldPw,newPassword:newPw,btnAction:"ChangePassword"},
                complete: function(msg) {
                    alert(msg.responseText);
                    $("#InputPassWord").val("");
                    $("#InputNewPassword").val("");
                    $("#re_InputPassWord").val("");
                }
            })
        }

    </script>
    <body onload="declare()">

        <c:if test="">

        </c:if>
        <jsp:include page="homeHeader.jsp"/>

        <br/>
        <div class="inside-botton-content-left" >
            <fieldset >
                <legend><h2>Đổi Mật Khẩu</h2></legend>
                <form action="ControllerServlet" method="POST" name="ChangepassForm"
                      id="changePassForm"  style="margin-left : 30">

                    <label>Mật khẩu hiện tại : </label><br/>
                    <input type="password" size ="40" name="txtPassword" id="InputPassWord" required placeholder="Mật khẩu" maxlength="20"/>
                    <input type="hidden" id="customerEmail" value ="${sessionScope.FULLNAME}"/><span class="required">* </span><br />
                    <div id="msgErrorPass" style="color: red;"></div>
                    <label>Mật khẩu mới : </label><br/>
                    <input type="password" size ="40" name="txtNewpassword" id="InputNewPassword" required placeholder="Mật khẩu mới" maxlength="20"/><span class="required">* </span>
                    <br/>
                    <label>Nhập lại mật khẩu : </label><br/>
                    <input name="re_InputPassWord" id="re_InputPassWord" type="password" size="40"
                           required placeholder="Nhập lại mật khẩu mới" maxlength="20"/><span class="required">* </span><br/><br/>

                    <div id="msgError" style="color: red;"></div>
                    <input type="button" value="ChangePassword" name="btnAction" id="btnSave"
                           onclick="changePassword()"/><br/><br/>
                    <a href="#" onclick="showChangepassword()" id="changepassLink">Cập Nhật Thông Tin</a><br />
                </form>
            </fieldset >
        </div>
        <br /> <br /> 

        <form action="ControllerServlet" method="POST"
              id="changeInfoForm" >
            <div class="inside-botton-content-left">
                <fieldset>
                    <legend><h2>Thông tin người dùng</h2></legend>
                    <label>Tên : </label><br/>
                    <input type="name" name="txtName" id="InputName" size ="40" required
                           placeholder="Tên" maxlength="50"/><span class="required">* </span> <br/>
                    <p>Giới Tính : <select name ="sex">
                            <option value =0>Nam</option>
                            <option value =1>Nữ</option>
                        </select>
                    </p>
                    <label>Ngày sinh : </label><br/>
                    <input name="birthday" id="birthdate" type="date" size="40" x-moz-errormessage="input
                           Date not in true format yyyy-mm-dd." placeholder="yyyy-mm-dd" pattern="[0-9]{4}-(0[1-9]|1[012])-(0
                           [1-9]|1[0-9]|2[0-9]|3[01])" required/><span class="required">* </span><br/>
                    <label>Điện thoại : </label><br/>
                    <input name="phone" id="phone" type="tel" size="40"  placeholder="Số điện thoại"/><span class="required">* </span><br/>
                    <label>Chiều cao (cm) : </label><br/>
                    <input name="height" id="height" type="hei" size="40" required
                           placeholder="Ví dụ: 160" maxlength="3"/>Cm<span class="required">* </span><br/>
                    <label>Cân nặng (kg): </label><br/>
                    <input name="weight" id="weight" type="wei" size="40" required
                           placeholder="Ví dụ: 55"maxlength="3"/> Kg<span class="required">* </span><br/><br/>
                    <input class="button-changeInfo" class="" type="submit" value="UpdateInformation" name="btnAction" id="btnSave"
                          />
                </fieldset>
            </div>
        </form>

    </body>
</html>
